package com.code.zjm.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

/**
 * Created by ZJM on 2017/5/21.
 */

public class BroadReceiverActivity extends BroadcastReceiver {

    private static final String TAG = "LocationBroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d(TAG, "Received Intent");

        if (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED))
        {
            Log.d(TAG, "Received KEY_LOCATION_CHANGED");

            Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
            onLocationChanged(context, location);
        }
        else if (intent.hasExtra(LocationManager.KEY_PROVIDER_ENABLED))
        {
            Log.d(TAG, "Received KEY_PROVIDER_ENABLED");

            if (intent.getExtras().getBoolean(LocationManager.KEY_PROVIDER_ENABLED))
            {
                onProviderEnabled(null);
            }
            else
            {
                onProviderDisabled(null);
            }
        }
        else if (intent.hasExtra(LocationManager.KEY_PROXIMITY_ENTERING))
        {
            Log.d(TAG, "Received KEY_PROXIMITY_ENTERING");

            if (intent.getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, false))
            {
                onEnteringProximity(context);
            }
            else
            {
                onExitingProximity(context);
            }
        }
        else if (intent.hasExtra(LocationManager.KEY_STATUS_CHANGED))
        {

        }
    }

    public void onLocationChanged(Context context, Location location) {}
    public void onProviderEnabled(String provider) {}
    public void onProviderDisabled(String provider) {}
    public void onEnteringProximity(Context context) {}
    public void onExitingProximity(Context context) {}
    public void onStatusChanged() {}
}
